package com.ls.server.service.model.strategy;

import com.ls.server.enums.ModelType;
import com.ls.server.service.model.strategy.impl.OpenAIModelStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 聊天模型策略工厂
 */
@Component
@RequiredArgsConstructor
public class ChatModelStrategyFactory {

    private final OpenAIModelStrategy openAIModelStrategy;


    /**
     * 策略缓存
     */
    private final Map<String, ChatModelStrategy> strategyCache = new ConcurrentHashMap<>();

    /**
     * 获取聊天模型策略
     *
     * @param modelType 模型类型
     * @return 聊天模型策略
     */
    public ChatModelStrategy getStrategy(String modelType) {
        return strategyCache.computeIfAbsent(modelType, type -> {
            ModelType mType = ModelType.getByCode(type);
            if (mType == null) {
                throw new RuntimeException("不支持的模型类型：" + type);
            }

            switch (mType) {

                case OPEN_AI:
                    return openAIModelStrategy;

                default:
                    throw new RuntimeException("不支持的模型类型：" + type);
            }
        });
    }
}
